﻿using System.Runtime.Serialization;
using UnityEngine;
using UnityEngine.Scripting;

namespace GMME.Model.Rtm
{
    [DataContract]
    public class RtmMessageContent
    {
        [DataMember(Name = "messageType")]
        [Preserve]
        public int MessageType { get; set; }

        [DataMember(Name = "messageString")]
        [Preserve]
        public string MessageString { get; set; }

        [DataMember(Name = "messageBytes")]
        [Preserve]
        public byte[] MessageBytes { get; set; }


#if UNITY_ANDROID
        internal static RtmMessageContent ConvertRtmMessageContent(AndroidJavaObject javaObject)
        {
            if (javaObject != null)
            {
                var result = new RtmMessageContent();
                result.MessageType = javaObject.Call<int>("getMessageType");
                result.MessageString = javaObject.Call<string>("getMessageString");
                result.MessageBytes = javaObject.Call<byte[]>("getMessageBytes");
                return result;
            }

            return null;
        }
#endif
    }
}